var Curctype;
var CurEpidCmdList = new Array;

function GetCurrAreEleData(curfloor,curatype)
{
	
	var rows=[];
	rows=$.grep(CurrElemArry,function(item, index){
		if(item.floorid == curfloor &&  item.atype == curatype)
		return true;
	},false);
	return rows;
}
function GetCurrFloorAreaData(curfloor)
{
	
	var data=[];
	data=$.grep(CurrAreaArry,function(item, index){
		if(item.floorid == curfloor)
		return true;
	},false);
	return data;
}
function DelFloorAction(currDelfloorid)
{
	$.each(CurrFloorArry,function(index,item){
			if(item.id == currDelfloorid){
				CurrFloorArry.splice(index, 1);
				return false;
			}
	})
	var delAreaids = [];
	
	$.each(CurrAreaArry,function(index,item){
			if(item.floorid == currDelfloorid){
				delAreaids.push({"delAreaid": item.id});
				return true;
			}
	})
	if(delAreaids.length != 0){
		$.each(delAreaids,function(index,item){
			var currDelAreaid = item.delAreaid;					   
			var DelOneAreaResult = DelAreaidAction(currDelAreaid);
		})							 
	}
	return true;
	
}
function DelAreaidAction(currDelAreaid)
{
	
	$.each(CurrAreaArry,function(index,item){
			if(item.id == currDelAreaid){
				CurrAreaArry.splice(index, 1);
				return false;
			}
	})
	
	if(CurrScenesArry.length != 0){
			
			var ers = [];
			ers = $.grep(CurrScenesArry,function(item, index){
				if(item.aredid == currDelAreaid)
					return true;
			},false);
			
			for (var l = 0; l < ers.length; l++) {
				$.each(CurrScenesArry,function(index,item){
						if(item.aredid == currDelAreaid){
							CurrScenesArry.splice(index, 1);
							return false;
						}
				})
			}
	}
	if(CurrElemArry.length != 0){
		
		var delepids = [];
		$.each(CurrElemArry,function(index,item){
			if(item.atype == currDelAreaid){
				delepids.push({"delepid": item.epid});
				return true;
			}
		})
		
		var dellength = delepids.length;
		
		if(delepids.length != 0){	
			$.each(delepids,function(index,item){
				var delepid = item.delepid;
				$.each(CurrElemArry,function(index,item){
						if(item.epid == delepid){
							CurrElemArry.splice(index, 1);
							return false;
						}
				})
				if(CurrElemCMDArry.length != 0){
					$.each(CurrElemCMDArry,function(index,item){
							if(item.epid == delepid){
								CurrElemCMDArry.splice(index, 1);
								return false;
							}
					})
				}
				if(CurrElemTriggerArry.length != 0){
					var Triggerers = [];
					Triggerers = $.grep(CurrElemTriggerArry,function(item, index){
						if(item.t_epid == delepid)
							return true;
					},false);
					
					for (var m = 0; m < Triggerers.length; m++) {
						$.each(CurrElemTriggerArry,function(index,item){
							if(item.t_epid == delepid){
								CurrElemTriggerArry.splice(index, 1);
								return false;
							}
						})
					}
					
				}
				
			})
		}
	}
	return true;
	
	
}
function DelEpAction(currareaname, currDelIds)
{	 
	  var Delrules = currDelIds.split(",");
	 
	for (var i = 0; i < Delrules.length; i++) {	
		var curscesetid = Delrules[i];
		var isDelStatus = false;
		
		$.each(CurrElemArry,function(index,item){
			if(item.epid == curscesetid){
				CurrElemArry.splice(index, 1);
				return false;
			}
		})
		if(CurrElemCMDArry.length != 0){
			$.each(CurrElemCMDArry,function(index,item){
				if(item.epid == curscesetid){
					CurrElemCMDArry.splice(index, 1);
					return false;
				}
			})
		}
		if(CurrElemTriggerArry.length != 0){
			
			var ers = [];
			ers = $.grep(CurrElemTriggerArry,function(item, index){
				if(item.t_epid == curscesetid)
					return true;
			},false);
			
			for (var l = 0; l < ers.length; l++) {
				$.each(CurrElemTriggerArry,function(index,item){					
					
					if(item.t_epid == curscesetid){						
						CurrElemTriggerArry.splice(index, 1);
						return false;					
					}
				})
			}
		}
		/*删除元件相关的报警器信息*/
	 if(CurrAlarmsArry.length != 0){
		 $.each(CurrAlarmsArry,function(index,item){
				if(item.epid == curscesetid){
					var id = item.id;
					if(curralarmid == id)
						curralarmid = '';
					CurrAlarmElemMap.remove(id);
					CurrAlarmsArry.splice(index, 1);
					return false;
				}
			})
	 }
	
	}
	$("#DeleteAllModal_delbtn").removeAttr("onclick");
	$('#DeleteAllModal').modal('hide');
	$('#table'+currareaname).bootstrapTable('load',{data:GetCurrAreEleData(currfloorid,currareaname)});
	
	if(LoadAlarmsIdSelect(curralarmid))
	$('#AlarmAreaListTable').bootstrapTable('load',{data:GetCurrAlarmAreaData(curralarmid)});
	
}
function RefreshTabData(currtableid)
{
	
	$('#table'+currtableid).bootstrapTable('load',{data:GetCurrAreEleData(currfloorid,currtableid)});
	
	
}
function ClearAddEpinfoDiv()
{
	$('#conf').val("");
	$('#modelcode').val("");
	$('#protocol').val("");
	$('#etype').val("");
	$('#etypename').val("");
	$('#ctrltype').val("");
	$('#ctypename').val("");
	$('#devtype').val("");
	$('#dtypename').val("");
	$('#floorname').val("");
	$('#atypename').val("");	
	$('#epid').val("");
	$('#floorid').val("");
	$('#atype').val("");
	$('#model').val("");
	$('#ctrlid').val("");
	$('#dchan').val("");
	$('#addr1').val("");
	$('#addr2').val("");
	FillSelectSetCurVal(confTypeMap,'conf','02');
	/*彩灯*/
	FillSelectSetCurVal(shapeTypeMap,'shape','1');
	FillSelectSetCurVal(dirTypeMap,'dir','1');
	$('#shapeTr').hide();
	$('#countTr').hide();
	$('#dirTr').hide();
	$('#distribTr').hide();
	$('#shape').val("");
	$('#count').val("");
	$('#distrib').val("");
	$('#distrib1').val("");
	$('#distrib2').val("");
	$('#distrib3').val("");
	$('#distrib4').val("");
	
	FillSelect(elemTypeMap,'etype');
	FillSelect(ctrlTypeMap,'ctrltype');
	FillSelect(LONinterfaceTypeMap,'devtype');
	$('#etypename').val(elemTypeMap.get("01"));
	DtypeInitByCtypeChange(1);
	McPtTrSwitch('02');
	$('#addr1Tr').show();
	$('#addr1Name').html("额外地址1");
	$('#addr2Tr').show();
	$('#addr2Name').html("额外地址2");
}
function AddEpInfo(currareaname)
{
	ClearAddEpinfoDiv();
	
	//$('#addr1,#addr2').removeAttr("placeholder");
	$('#devtype').removeAttr("validate");	
	$('#model').removeAttr("readonly");
	$('#ctrltype').removeAttr("readonly");
	$('#devtype').removeAttr("readonly");
	$('#etype').removeAttr("readonly");	
	$('#modelcode').removeAttr("readonly");
	$('#protocol').removeAttr("readonly");
	$('#conf').removeAttr("readonly");
	$('#etypename').removeAttr("readonly");
	$('#etypename').removeAttr("disabled");
	$('#conf').removeAttr("disabled");
	$('#modelcode').removeAttr("disabled");
	$('#protocol').removeAttr("disabled");
	$('#model').removeAttr("disabled");
	$('#ctrltype').removeAttr("disabled");
	$('#devtype').removeAttr("disabled");
	$('#etype').removeAttr("disabled");
	
	$('#shape').removeAttr("readonly");
	$('#count').removeAttr("readonly");
	$('#dir').removeAttr("readonly");
	$('#distrib').removeAttr("readonly");
	$('#distrib1').removeAttr("readonly");
	$('#distrib2').removeAttr("readonly");
	$('#distrib3').removeAttr("readonly");
	$('#distrib4').removeAttr("readonly");
	$('#shape').removeAttr("disabled");
	$('#count').removeAttr("disabled");
	$('#dir').removeAttr("disabled");
	$('#distrib').removeAttr("disabled");
	$('#distrib1').removeAttr("disabled");
	$('#distrib2').removeAttr("disabled");
	$('#distrib3').removeAttr("disabled");
	$('#distrib4').removeAttr("disabled");
	$('#distrib1').removeAttr("validate");
	$('#distrib2').removeAttr("validate");
	$('#distrib3').removeAttr("validate");
	$('#distrib4').removeAttr("validate");
			
	$('#epAddModal_addbtn').removeAttr("onclick");
	$('#epAddModalLabelTitle').html("添加设备信息");
	$('#epAddModal_addbtn').text("添加");
	$('#epAddModal .error').removeClass("error");
	$('#epAddModal .text-error').remove();
	$('#epAddModal').modal('show');
	$("#epAddModal_addbtn").attr("onclick","AddEpAction('"+currareaname+"');");
	$('#devModelTr').show();
	
	$('#ctrlid').val("1");
	//$('#ctrlid').attr("readOnly","true");
	InitmodelselectSet();
	
}
function DelEpInfo(currareaname)
{
	 var currDelIds = "";
	 var rows = $('#table'+currareaname).bootstrapTable('getSelections');
	for (var i = 0; i < rows.length; i++) {
		currDelIds += rows[i].epid + ',';
	}
	currDelIds = currDelIds.substring(0, currDelIds.length - 1);
	
   
	if (currDelIds == "" || currDelIds.length == 0) {
		alert("请选择您要删除的记录！");
		return;
	}	
	 $('#DeleteAllModal').removeClass('modalSence');
	 $('#DeleteAllModal').modal('show');
	 $("#DeleteAllModal_delbtn").attr("onclick","DelEpAction('"+currareaname+"','"+currDelIds+"');");
}
function TabContentDiveach()
{
	$('#myTabContent > div').each(function(i){
		if(i == 0)
			$(this).show();
		else
			$(this).hide();
	});
}
function myTabContentDivShowFirst()
{
	
	$.each(NavLiIds,function(n,value) {	
		if(n == 0)
			$('#'+value).show();
		else
			$('#'+value).hide();
		
	});
}
function LoadTables()
{
	var tableIDLength = parseInt(tableIds.length);
	$.each(tableIds,function(n,value) {
	
		initTables(value);
		
	});
}
function initSelect(currusername)
{
	
	FillSelect(areaTypeMap,'areaAddselect');
	FillSelect(confTypeMap,'conf');
	FillSelect(elemTypeMap,'etype');
	FillSelect(ctrlTypeMap,'ctrltype');
	//FillSelect(ModelTypeMap,'model');
	FillSelect(cmdTypeMap,'cmdctype');
	FillSelect(LONinterfaceTypeMap,'devtype');
	FillSelect(sceneTypeMap,'sceneType');
	
}
function LoadSelect(sel_data)
{
	
	$("#SelectFloor").empty();
	$.each(selarea_data.Rows, function (index, item) {
		
		$("#SelectFloor").append("<option value="+item.floorid+">"+item.floorname+"</option>"); 
	});
	$("#SelectFloor").val(currfloorid);
	$("#SelectFloor option[value='" + currfloorid + "']").attr("selected","selected");
}
function initAreaType(currusername,currfloorid)
{
	return true;
}

function LoadAreaType(curfloorarea_data)
{		
	var currfid = 'floor' + currfloorid;
	$('.well').attr("id",currfid);
	
	LoadNavtabs(curfloorarea_data);
}
function LoadNavtabs(area_data)
{	
	area_data = area_data.sort(function(a, b){  //按id排序
                    		return (a.id - b.id);
                		});
	$("#myTab").find("li").remove();
	$('#myTabContent').empty();
	
	$.each(area_data, function (index, item) {
		//var liid = areatypeLiIDMap(item.atype);
		var liid = 'areaType' + item.id;
		if(index == 0){
			
			$("#myTab").append("<li class='active'><a href='#"+ liid +"' data-toggle='tab' onclick=RefreshTabData('"+item.id+"')>"+item.name+"</a></li>");
			}
		else
			$("#myTab").append("<li><a href='#"+ liid +"' data-toggle='tab' onclick=RefreshTabData('"+item.id+"')>"+item.name+"</a></li>");
		LoadeachTabContentDiv(index,item.id,liid,item.name);
		var tableid = 'table' + item.id;
		
		//NavLiIds.push(liid);
		
		tableIds.push(tableid);
	});
	//$("#myTab").append("<li>&nbsp;&nbsp;<button class='btn-flat' data-toggle='modal' data-target='#areaAddModal' id='areabtnAdd'><i class='icon-plus'></i>添加区域</button>&nbsp;&nbsp;<a role='button'  class='btn-flat danger pull-right' id='areabtnDel'><i class='icon-remove'></i>删除区域</a></li>");
	LoadTables();
	//myTabContentDivShowFirst();
}
function LoadeachTabContentDiv(num,atypeid,atypemap,areaname)
{	
	var tabContent = "";
	if(num == 0)
		tabContent = tabContent + "<div class='row-fluid tab-pane fade in active' id='"+atypemap +"'>";
	else
		tabContent = tabContent + "<div class='row-fluid tab-pane fade' id='"+atypemap +"'>";
	tabContent = tabContent + "<form id='formtab"+atypeid +"'>";
	tabContent = tabContent + "<div><h4 style='margin-left:10px;margin-bottom:15px;'>" +areaname +"设备列表&nbsp;&nbsp;&nbsp;&nbsp;<a role='button' class='btn-flat' onclick=AddEpInfo('"+atypeid+"')><i class='icon-plus'></i>添加</a>&nbsp;&nbsp;&nbsp;&nbsp;<a role='button'  class='btn-flat danger' onclick=DelEpInfo('"+atypeid+"')><i class='icon-remove'></i>删除</a>&nbsp;&nbsp;</h4></div>";
	tabContent = tabContent + "<div ><table id='table"+ atypeid +"'></table></div>";
	tabContent = tabContent + "</form></div>";
	$("#myTabContent").append(tabContent);
	
}
function ShowEpidEditInfo(editepid)
{
	$('#devModelTr').hide();
	var currareaid;
	$('#epAddModal .error').removeClass("error");
	$('#epAddModal .text-error').remove();
	$('#epAddModalLabelTitle').html("修改设备信息");
	$('#epAddModal_addbtn').text("修改");
	$("#conf").empty();
	$("#etype").empty();
	$("#model").empty();
	$("#ctrltype").empty();
	$("#devtype").empty();
	FillNoChoosedSelect(confTypeMap,'conf');
	FillNoChoosedSelect(elemTypeMap,'etype');
	FillNoChoosedSelect(ModelTypeMap,'model');
	FillNoChoosedSelect(ctrlTypeMap,'ctrltype');
	//FillNoChoosedSelect(interfaceTypeMap,'devtype');
	$("#shape").empty();
	$("#dir").empty();
	FillNoChoosedSelect(shapeTypeMap,'shape');
	FillNoChoosedSelect(dirTypeMap,'dir');
	$('#shapeTr').hide();
	$('#countTr').hide();
	$('#dirTr').hide();
	$('#distribTr').hide();
	$('#shape').val("");
	$('#count').val("");
	$('#distrib').val("");
	$('#distrib1').val("");
	$('#distrib2').val("");
	$('#distrib3').val("");
	$('#distrib4').val("");
	$.each(CurrElemArry,function(index,item){					
					
		if(item.epid == editepid){						
			currareaid = item.atype;
			$('#floorname').val(item.floorname);
			$('#floorid').val(item.floorid);
			$('#atypename').val(item.atypename);	
			$('#atype').val(item.atype);
			$('#epid').val(item.epid);
			$('#etype').val(item.etype);
			$("#etype option[value='" + item.etype + "']").attr("selected","selected");
			$('#etypename').val(item.etypename);
			$('#model').val(item.model);
			$("#model option[value='" + item.model + "']").attr("selected","selected");
			//$('#modelname').val(item.modelname);
			$('#ctrltype').val(item.ctrltype);
			$("#ctrltype option[value='" + item.ctrltype + "']").attr("selected","selected");
			$('#ctypename').val(item.ctypename);
			DtypeInitNoChooseByCtypeChange(parseInt(item.ctrltype));
			if(item.ctrltype == 3){
				$('#devtype').val("");
				$('#dtypename').val("");
			}
			else{
				
				$('#devtype').val(item.devtype);
				$("#devtype option[value='" + item.devtype + "']").attr("selected","selected");
				$('#dtypename').val(item.dtypename);
				DchanSetValidateByDtypeChange(item.ctrltype, item.devtype);
			}
			$('#ctrlid').val(item.ctrlid);
			
			$('#dchan').val(item.dchan);
			if((item.ctrltype == 2 && item.dchan != 4 && item.dchan != 5) || (item.ctrltype == 5) || (item.ctrltype == 4 &&  item.devtype == 2)){
				$("#dchan option[value='" + item.dchan + "']").attr("selected","selected");
			}
			$('#model').val(item.model);
			$('#addr1').val(item.addr1);
			$('#addr2').val(item.addr2);
			if(item.addr1 == '0'){
				$('#addr1Tr').hide();
				$('#addr1Name').html("额外地址1");
			}
			else{
				$('#addr1Tr').show();
				$('#addr1Name').html("额外地址1");
			}
			if(item.addr2 == '0'){
				$('#addr2Tr').hide();
				$('#addr2Name').html("额外地址2");
			}
			else{
				$('#addr2Tr').show();
				$('#addr2Name').html("额外地址2");
			}
			$('#conf').val(item.conf);
			$("#conf option[value='" + item.conf + "']").attr("selected","selected");
			McPtTrSwitch(item.conf);
			$('#modelcode').val(item.modelcode);
			$('#protocol').val(item.protocol);
			var checkStr = item.model.substring(0,6);
			if(checkStr == '0x0102')
			{
				$('#count').val(item.count);
				$('#shape').val(item.shape);
				$("#shape option[value='" + item.shape + "']").attr("selected","selected");
				$('#shapeTr').show();
				//$('#countTr').show();
				$('#distrib').val(item.distrib);
				if(item.shape == '3')
				{
					var distrib = item.distrib.split(",");
					
					$('#distrib1').val(distrib[0]);
					$('#distrib2').val(distrib[1]);
					$('#distrib3').val(distrib[2]);
					$('#distrib4').val(distrib[3]);
					$('#dir').val(item.dir);
					$("#dir option[value='" + item.dir + "']").attr("selected","selected");
					$('#dirTr').show();
					$('#distribTr').show();
				}
			}
			return false;					
		}
	})
	$("#epAddModal_addbtn").attr("onclick","EditEpInfoAction('"+editepid+"','"+currareaid+"');");
	/*var currctype = $( '#ctrltype' ).val();
	if(currctype == 2 )
		$('#dtypeTr').show();
	else
		$('#dtypeTr').hide();*/
	$('#shape').attr("readonly",true);
	$('#count').attr("readonly",true);
	$('#dir').attr("readonly",true);
	$('#distrib').attr("readonly",true);
	$('#distrib1').attr("readonly",true);
	$('#distrib2').attr("readonly",true);
	$('#distrib3').attr("readonly",true);
	$('#distrib4').attr("readonly",true);
	$('#shape').attr("disabled","disabled");
	$('#count').attr("disabled","disabled");
	$('#dir').attr("disabled","disabled");
	$('#distrib').attr("disabled","disabled");
	$('#distrib1').attr("disabled","disabled");
	$('#distrib2').attr("disabled","disabled");
	$('#distrib3').attr("disabled","disabled");
	$('#distrib4').attr("disabled","disabled");
	$('#distrib1').removeAttr("validate");
	$('#distrib2').removeAttr("validate");
	$('#distrib3').removeAttr("validate");
	$('#distrib4').removeAttr("validate");
	
	$('#model').attr("readonly",true);
	$('#ctrltype').attr("readonly",true);
	$('#devtype').attr("readonly",true);
	$('#etype').attr("readonly",true);	
	$('#modelcode').attr("readonly",true);
	$('#protocol').attr("readonly",true);
	$('#conf').attr("readonly",true);
	//$('#etypename').attr("readonly",true);
	//$('#etypename').attr("disabled","disabled");
	$('#conf').attr("disabled","disabled");
	$('#modelcode').attr("disabled","disabled");
	$('#protocol').attr("disabled","disabled");
	$('#model').attr("disabled","disabled");
	$('#ctrltype').attr("disabled","disabled");
	$('#devtype').attr("disabled","disabled");
	$('#etype').attr("disabled","disabled");
	//$('#addr1,#addr2').removeAttr("placeholder");
	$('#epAddModal').modal('show');
	
}
function EditEpInfoAction(editepid,currareaid)
{
	var ispass = validateRow('epAddModaltable');
	if(!ispass){
		
		return;
	}
	else{
		 var isAlready = false;
		 var ctrltype = $('#ctrltype').val();
		 var etypename = $('#etypename').val();
		 var ctrlid = $('#ctrlid').val();
		 var devtype = $('#devtype').val();
		 var dchan = $('#dchan').val();
		 var addr1 = $('#addr1').val();
		 var addr2 = $('#addr2').val();
		 if(CurrElemArry.length != 0){
			var Cur = [];
			Cur = $.grep(CurrElemArry,function(item, index){
														   
				if(item.ctrltype == ctrltype && item.etypename == etypename && item.ctrlid == ctrlid && item.devtype == devtype && item.dchan == dchan && item.addr1 == addr1 && item.addr2 == addr2)
					return true;
			},false);
			if(Cur.length != 0)
				isAlready = true;
		 }
		 if(isAlready == true)
		 {
			var errorMsg = "该通道和地址的设备已经存在";
			$('#dchan').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
			return false;
		 }else{
			
			 
			 $.each(CurrElemArry,function(index,item){
				if(item.epid == editepid){
					CurrElemArry.splice(index, 1);
					return false;
				}
			 })
			 
			$('#model').removeAttr("readonly");
			$('#ctrltype').removeAttr("readonly");
			$('#devtype').removeAttr("readonly");
			$('#etype').removeAttr("readonly");
			$('#modelcode').removeAttr("readonly");
			$('#protocol').removeAttr("readonly");
			$('#conf').removeAttr("readonly");
			$('#etypename').removeAttr("readonly");
			$('#etypename').removeAttr("disabled");
			$('#conf').removeAttr("disabled");
			$('#modelcode').removeAttr("disabled");
			$('#protocol').removeAttr("disabled");
			$('#model').removeAttr("disabled");
			$('#ctrltype').removeAttr("disabled");
			$('#devtype').removeAttr("disabled");
			$('#etype').removeAttr("disabled");
			//$('#addr1,#addr2').removeAttr("placeholder");
			
			$('#shape').removeAttr("readonly");
			$('#count').removeAttr("readonly");
			$('#dir').removeAttr("readonly");
			$('#distrib').removeAttr("readonly");
			$('#distrib1').removeAttr("readonly");
			$('#distrib2').removeAttr("readonly");
			$('#distrib3').removeAttr("readonly");
			$('#distrib4').removeAttr("readonly");
			$('#shape').removeAttr("disabled");
			$('#count').removeAttr("disabled");
			$('#dir').removeAttr("disabled");
			$('#distrib').removeAttr("disabled");
			$('#distrib1').removeAttr("disabled");
			$('#distrib2').removeAttr("disabled");
			$('#distrib3').removeAttr("disabled");
			$('#distrib4').removeAttr("disabled");
			
			var table = $('#epAddModalform').serializeObject();
			CurrElemArry.push(table);
			
			$('#devModelTr').show();
			$('#epAddModal').modal('hide');			
			$('#epAddModalLabelTitle').html("添加设备信息");
			$('#epAddModal_addbtn').text("添加");
			$('#table'+currareaid).bootstrapTable('load',{data:GetCurrAreEleData(currfloorid,currareaid)});
		 }
	}
	
}
function initTables(tabid)
{
var tid = tabid.substring(tabid.indexOf('table')+5,tabid.length);
$('#'+tabid).bootstrapTable({							
	data: GetCurrAreEleData(currfloorid,tid),
	//height: 540,
	striped: true,
	dataType: "json",
	pagination: true,	
	singleSelect: false,	
	contentType: 'application/json',
	pageSize: 5,
	pageNumber:1,
	pageList: [5,10, 25, 50, 100],
	showRefresh: false,
	showToggle: false,	
	search: false, //不显示 搜索框
	showColumns: false, //不显示下拉框（选择显示的列）
	sidePagination: "client", //服务端请求
	
	columns: [
		{
                    field: 'state',
                    checkbox: true
         }, 	
		{
			field: 'epid',	
			title: '设备ID',	
			width: '5%',		
			align: 'center',	
			valign: 'middle',
			formatter: EditInfoFormatter,
			sortable: false	
		},
		{
			field: 'etypename',	
			title: '设备名称',	
			width: '10%',		
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		
		{
			field: 'atype',	
			title: '位置信息',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',
			formatter: AreaInfoFormatter,
			sortable: false	
		},
		{
			title: '通道信息',
			field: 'dchan',	
			width: '20%',
			align: 'center',	
			valign: 'middle',
			formatter: ChannelInfoFormatter,
			sortable: false	
		},
		{
			field: 'ctrltype',	
			title: '厂商信息',	
			width: '20%',	
			align: 'center',	
			valign: 'middle',
			formatter: ExtraInfoFormatter,
			sortable: false	
		},
		{
			title: '命令配置',
			field: 'operate',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',	
			formatter: CMDFormatter,				
			sortable: false	
		},
		{
			title: '添加/查看联动',
			field: 'operate',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',	
			formatter: operateFormatter,				
			sortable: false	
		}
	]
	
});
//$("#formtab1").find(".fixed-table-container").css("height","485px");
}
function EditInfoFormatter(value, row, index) {
            return ['<a target="mainIframe" title="点击可以修改该EPID的通道和地址信息" onclick="ShowEpidEditInfo(\''+row.epid+'\')"><i class="icon-edit"></i>'+row.epid+'</a>'
                    ].join('');
}
function AreaInfoFormatter(value, row, index) {
            return ['所属楼层：'+ row.floorname + '<br>所属区域：'+row.atypename
                    ].join('');
}
function ChannelInfoFormatter(value, row, index) {
	if(row.ctrltype == 3 || row.ctrltype == '3')
            return ['控制器通道：'+ row.ctrlid + '<br>所属控制器类型：'+row.ctypename+'<br>设备通道：'+row.dchan
                    ].join('');
	else
			return ['控制器通道：'+ row.ctrlid + '<br>所属控制器类型：'+row.ctypename+'<br>所属接口类型：'+row.dtypename+'<br>设备通道：'+row.dchan
                    ].join('');
			
}
function ExtraInfoFormatter(value, row, index) {
            return ['厂商型号：'+ row.model + '<br>额外地址1：'+row.addr1+'<br>额外地址2：'+row.addr2
                    ].join('');
}

function sublistresponseHandler(res) {
	
	return {
	"rows": res,
	"total": res.length
	};

}
//传递的参数
function sublistqueryParams(params) {
	return {
		pagesize: params.limit,
		page: params.pageNumber,
	};
}

function operateFormatter(value, row, index) {
           /*return ['<ul class="actions"><li onclick="UserMng('+row.epid+ ',' + index+')"><i class="table-edit" ></i></li><li class="last" onclick="DelOneUserDiv(\''+ row.epid+'\')"><i class="table-settings"></i></li></ul>'
							].join('');*/
		   return '<a class="btn-flat gray"  style="text-decoration:none" onclick="GetTriggerFrom(\''+row.epid+'\')">联动配置</a>';
}
function CMDFormatter(value, row, index) {
return '<a class="btn-flat gray" style="text-decoration:none" onclick="GetCMDFrom(\''+row.epid+'\',\''+row.model+'\')">命令配置</a>';

}

function roleFormatter(value, row, index) {
return '<button class="btn-flat success pull-right" data-toggle="button" onclick="ChangeRole('+ row.epid+ ',1' +')">切换角色</button>';           
}
function releaseFormatter(value, row, index) {
            return ['<a role="button" data-toggle="modal" onclick="ChangeRole('+ row.username+',' + row.mark + ')"><i class="icon-pencil"></i></a>',
					'<a href="#userReleaseModal" role="button" data-toggle="modal"><i class="icon-remove"></i></a>'
                    ].join('');
}
function RefleshAllDataCurrfloor(currusername,currfloorid)
{
	$("#div_find").hide();
	$(".well").show();
	initSelect(currusername);
	initAreaType(currusername,currfloorid);	
	$('#myTab a:first').tab('show');
	
}
function GetCurrl880interfaceRangeData(curcode)
{
	
	var rows=[];
	$.each(Initl880interfaceArray.param,function(index,item){
			if(item.code == curcode){
				rows = item.i;
				return false;
			}
	})
	
	return rows;
}
function GetCurrNICODMX512interfaceRangeData(curcode)
{
	
	var rows=[];
	$.each(InitNICODMX512interfaceArray.param,function(index,item){
			if(item.code == curcode){
				rows = item.i;
				return false;
			}
	})
	
	return rows;
}
function GetCurrl830linterfaceRangeData(curcode)
{
	
	var rows=[];
	$.each(Initl830linterfaceArray.param,function(index,item){
			if(item.code == curcode){
				rows = item.i;
				return false;
			}
	})
	
	return rows;
}
function InitDchanSelecthtml(selectarry,selectId)
{
		
		$("#" + selectId).empty();
		var selectedValue;
		var length = selectarry.length;
		
		$.each(selectarry, function (index, item) {
			if(index == 0)
				selectedValue = item.val;
			$("#" + selectId).append("<option value="+item.val+">"+item.name+"</option>"); 
	});	
		$("#" + selectId).val(selectedValue);
		$("#" + selectId + " option[value='" + selectedValue + "']").attr("selected","selected");	
	
}
function InitmodelselectSet()
{
	var etype=$("#etype").children("option:selected").val();
	var CurModelArray=GetCurModelArrayData(etype);
	var CurCmdArray=GetCurCmdArrayData(CurModelArray);
	FillSelectCmdModel(CurCmdArray,'modelselect');
	var curcmdid=$("#modelselect").children("option:selected").val();
	if(curcmdid!= "" && curcmdid != undefined && curcmdid != null){
		RenderModelInfo();	
	}
	else{
		$('#devModelTr').hide();
		$('#modelcodeTr').show();
		$('#protocolTr').show();
		$('#confTr').show();
		$('#addr1').val("");
		$('#addr2').val("");
		$('#addr1Tr').show();
		$('#addr1Name').html("额外地址1");
		$('#addr2Tr').show();
		$('#addr2Name').html("额外地址2");
		
	}
	var currconf = $("#conf").val();
	if(currconf == '02'){
		$('#modelcode').val('00');
		$('#protocol').val('00');
		$('#modelcodeTr').hide();
		$('#protocolTr').hide();
	}
	
	/*var model = $("#modelselect").children("option:selected").attr("data-model");
	var conf=model.substring(2,4);
	var mc=model.substring(6,8);
	var pt=model.substring(8,10);
	$("#modelcode").val(mc);
	$("#protocol").val(pt);
	$('#modelcode').attr("readOnly","true");
	$('#protocol').attr("readOnly","true");
	$("#conf"+" option[value='" + conf + "']").attr("selected","selected");*/
}